package com.ruoyi.yl.controller;


import com.ruoyi.yl.common.Result;
import com.ruoyi.yl.domain.YlDrug;
import com.ruoyi.yl.service.DrugInfoMaintenanceService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import static com.ruoyi.yl.constant.YlConstant.*;
import java.util.List;

/**
 * @Author: linKe
 * @Date: 2022/2/17 17:24
 * @FileName: DrugChangePriceManageController
 * @version: 1.0
 * @Description: 药品信息维护
 */
@RestController
@RequestMapping("/drugInfoMaintenance")
public class DrugInfoMaintenanceController {
    @Resource
    private DrugInfoMaintenanceService drugInfoMaintenanceServiceImpl;

    /**
     * 查询所有药品
     */
    @GetMapping("/getAll")
    public Result<List<YlDrug>> getAll() {
        List<YlDrug> all = drugInfoMaintenanceServiceImpl.getAll();
        return new Result<>(OP_SUCCESS_CODE, OP_SUCCESS_MSG, all);
    }

    /**
     * 根据处方类型查药品
     */
    @GetMapping("/getDrugsByType/{id}")
    public Result<List<YlDrug>> getDrugsByType(@PathVariable("id") Long id) {
        List<YlDrug> drugsByType = drugInfoMaintenanceServiceImpl.getDrugsByType(id);
        return new Result<>(OP_SUCCESS_CODE, OP_SUCCESS_MSG, drugsByType);
    }

    /**
     * 根据药品状态查药品
     */
    @GetMapping("/getDrugsByStatus/{id}")
    public Result<List<YlDrug>> getDrugsByStatus(@PathVariable("id")Long id) {
        List<YlDrug> drugsByStatus = drugInfoMaintenanceServiceImpl.getDrugsByStatus(id);
        return new Result<>(OP_SUCCESS_CODE, OP_SUCCESS_MSG, drugsByStatus);
    }

    /**
     * 根据创建时间查药品
     */
    @GetMapping("/getDrugsByTime")
    public Result<List<YlDrug>> getDrugsByTime(String time) {
        String time1 = new String("2020-12-17");
        String a = new String(" 00:00:00");
        String b = new String(" 23:59:59");
        String date1 = time1 + a;
        String date2 = time1 + b;
        List<YlDrug> drugsByTime = drugInfoMaintenanceServiceImpl.getDrugsByTime(date1, date2);
        return new Result<>(OP_SUCCESS_CODE, OP_SUCCESS_MSG, drugsByTime);
    }

    /**
     * 根据药品名、编号、生产厂家模糊查询药品
     */
    @GetMapping("/getDrugsByLike")
    public Result<List<YlDrug>> getDrugsByLike(String dsc) {
        List<YlDrug> drugsByLike = drugInfoMaintenanceServiceImpl.getDrugsByLike(dsc);
        return new Result<>(OP_SUCCESS_CODE, OP_SUCCESS_MSG, drugsByLike);
    }

    @PostMapping("/addDrug")
    public Result<Integer> addDrug(YlDrug drug) {
        YlDrug drug1 = new YlDrug()
               /* .setNumber(21312312L)
                .setPrescriptionType(PrescriptionType.WEST_PRESCRIPTION)
                .setDrugType(new DrugType().setId(1L))
                .setBarCode(1232132L)
                .setDrugName("六味地黄丸")
                .setSpell("liuweidihuangwang")
                .setDrugForm(new DrugForm().setId(1L))
                .setSpecification("12克/盒")
                .setCommonJudge(CommonJudge.IS)
                .setInvoice(new Invoice().setId(1l))
                .setPermitNumber("sdasd")
                .setFactory(new Factory().setId(1L))
                .setStock(20)
                .setCreateTime(LocalDateTime.now())
                //.setDrugStatus(CommonStatus.ACTIVATED)
                //.setPackUnit(new PackUnit().setId(1L))
               // .setBaseCoefficient(3)
                .setDoseCoefficient(12)
                .setPurchasePrice(new BigDecimal("5.2"))
                .setSalePrice(new BigDecimal("7.2"))
                .setSeparable(CommonJudge.NOT)
                .setDrugUsage(new DrugUsage().setId(1L))
                .setSingleDose(2)
                .setFrequency(3)
                .setDrugDay(Day.ONE)
                .setTotal(34)
                .setStockMax(12)
                .setStockMin(12)
                .setLocation(21)
                .setValidityInform(LocalDate.now())
                .setDescription("没啥")
                .setRemark("没啥备注")
                .setAdjustCount(0)*/;
        int id = drugInfoMaintenanceServiceImpl.addDrug(drug1);
        return new Result<>(OP_SUCCESS_CODE, OP_SUCCESS_MSG, id);
    }

    @GetMapping("/getOneById")
    public Result<YlDrug> getOneById(Long id) {
        YlDrug oneById = drugInfoMaintenanceServiceImpl.getOneById(1L);
        return new Result<>(OP_SUCCESS_CODE, OP_SUCCESS_MSG, oneById);
    }

    /**
     * 根据药品修改药品
     *
     * @return
     */
    @PutMapping("/updateDrug")
    public Result<String> updateDrug(Long id, YlDrug drug) {
        YlDrug drug1 = new YlDrug()
                /*.setNumber(21312312L)
                .setPrescriptionType(PrescriptionType.WEST_PRESCRIPTION)
                .setDrugType(new DrugType().setId(1L))
                .setBarCode(1232132L)
                //.setName("大力丸")
                .setSpell("liuweidihuangwang")
                .setDrugForm(new DrugForm().setId(1L))
                .setSpecification("12克/盒")
                .setCommonJudge(CommonJudge.IS)
                .setInvoice(new Invoice().setId(1l))
                .setPermitNumber("sdasd")
                .setFactory(new Factory().setId(1L))
                .setStock(20)
                .setCreateTime(LocalDateTime.now())
                .setStatus(CommonStatus.ACTIVATED)
                .setPackUnit(new PackUnit().setId(1L))
                .setBaseCoefficient(3)
                .setDoseCoefficient(12)
                .setPurchasePrice(new BigDecimal("5.2"))
                .setSalePrice(new BigDecimal("7.2"))
                .setSeparable(CommonJudge.NOT)
                .setDrugUsage(new DrugUsage().setId(1L))
                .setSingleDose(2)
                .setFrequency(3)
                .setDay(Day.ONE)
                .setTotal(34)
                .setStockMax(12)
                .setStockMin(12)
                .setLocation(21)
                .setValidityInform(LocalDate.now())
                .setDescription("没啥")
                .setRemark("没啥备注")
                .setAdjustCount(0)*/;
        drugInfoMaintenanceServiceImpl.updateDrug(3L, drug1);
        return new Result<>(OP_SUCCESS_CODE, OP_SUCCESS_MSG, "结果");
    }
}
